//
//  ZHStarView.m
//  ZhiHuiLvYouCustomer
//
//  Created by 曾浩 on 15/11/13.
//  Copyright © 2015年 ZengHao. All rights reserved.
//

#import "ZHStarView.h"

@implementation ZHStarView
- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        //默认的星星的大小是 13.0f
        self.starSize = 13.0f;
        //未点亮时的颜色是 灰色的
        self.emptyColor = [UIColor colorWithRed:167/255.0 green:167/255.0 blue:167/255.0 alpha:1];
        //点亮时的颜色是 亮黄色的
        self.fullColor = [UIColor orangeColor];
        //UIColorRGBA(255, 121, 22,1)
        self.maxStar = 100;
    }
    return self;
}
//重绘视图
- (void)drawRect:(CGRect)rect{
    CGContextRef context = UIGraphicsGetCurrentContext();
    NSString* stars = @"★★★★★";
    
    rect = self.bounds;
    UIFont *font = [UIFont boldSystemFontOfSize:_starSize];
    CGSize starSize = [stars sizeWithAttributes:@{NSFontAttributeName:font}];
    
    rect.size=starSize;
    [_emptyColor set];
    [stars drawInRect:rect withFont:font];
//    [stars drawInRect:rect withAttributes:@{NSFontAttributeName:font}];
    CGRect clip = rect;
    clip.size.width = clip.size.width * _showStar / _maxStar;
    CGContextClipToRect(context,clip);
    [_fullColor set];
    [stars drawInRect:rect withFont:font];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
     Drawing code
}
*/

- (void) setShowStar:(NSInteger)showStar {

    _showStar = showStar;
    [self setNeedsDisplay];
}

@end
